package com.spzx.order.controller;

import com.spzx.cart.api.RemoteCartService;
import com.spzx.cart.domain.CartInfo;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.RequiresLogin;
import com.spzx.order.domain.OrderForm;
import com.spzx.order.domain.TradeVo;
import com.spzx.order.service.IOrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "订单接口管理")
@RestController
@RequestMapping("/orderInfo")
public class OrderInfoController extends BaseController {

	@Autowired
	private IOrderInfoService orderInfoService;
	@Autowired
	private RedisTemplate redisTemplate;

	// GET http://192.168.110.55:8080/order/orderInfo/trade
	@GetMapping("trade")
	@Operation(summary = "获取交易详情信息")
	public AjaxResult trade() {
		return success(orderInfoService.createTrade());
	}

	// 请求网址:
	// http://192.168.110.55:8080/order/orderInfo/submitOrder
	// 请求方法:
	// POST
	@Operation(summary = "提交订单")
	@RequiresLogin
	@PostMapping("submitOrder")
	public AjaxResult submitOrder(@RequestBody OrderForm orderForm) {
		Long orderId = orderInfoService.submitOrder(orderForm);
		return success(orderId);
	}


	// http://192.168.110.55:8080/order/orderInfo/getOrderInfo/23
	// Request Method: GET
	@Operation(summary = "获取订单信息")
	@GetMapping("getOrderInfo/{orderId}")
	public AjaxResult getOrderInfo(@PathVariable Long orderId) {
		return success(orderInfoService.getOrderInfo(orderId));
	}
	// http://192.168.110.55:8080/order/orderInfo/userOrderInfoList/1/10?orderStatus=
	// Request Method: GET
	@Operation(summary = "获取用户订单列表")
	@GetMapping("userOrderInfoList/{pageNum}/{pageSize}")
	@RequiresLogin
	public AjaxResult userOrderInfoList(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestParam(required = false) Integer orderStatus) {
		return success(orderInfoService.userOrderInfoList(pageNum, pageSize, orderStatus));
	}

}
